package leetcode.editor.cn.dsa28_apply;

import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        //String A = "aaaabbbbccccddddeeee";
        String A = "aaaaaaaaaaaaaaaaaaaa";
        int[] count = new int[6];
        for (int i = 0; i < 6; i++) {
            count[i] = -1;
        }
        for (int i = 0; i < A.length(); i++) {
            count[A.charAt(i) - 'a']++;
        }
        int[] start = new int[6];
        int preSum = 0;
        for (int i = 0; i < 6; i++) {
            start[i] = preSum;
            preSum += count[i];
        }
        int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
        char[] array = A.toCharArray();
        for (int i = 0; i < array.length; i++) {
            int index = array[i] - 'a';
            if (count[index] != 0) {
                array[i] = (char)('z' - start[index] - count[index]);
                count[index]--;
            }
        }
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));
    }
}
